cmake_minimum_required(VERSION 3.5)
project(pureclog C)

set(CMAKE_VERBOSE_MAKEFILE on)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
#	set(CMAKE_C_COMPILER "gcc")
#	set(CMAKE_CXX_COMPILER "g++")
	set(CMAKE_C_FLAGS "-g -pthread")
endif()

if(WIN32)
set(CMAKE_MSC_VER_EXPORT_ALL_SYMBOLS ON)
elseif()

endif()


set(PURECLOGSRC
  src/pureclog.c
)

set(TESTSRC
  test/test.c
)

include_directories(
  ./include
  ../ring_queue/include
  ${PROJECT_BINARY_DIR}
)
add_library(pureclog STATIC ${PURECLOGSRC})
message(STATUS "the binary dir:${CMAKE_BINARY_DIR}")
link_directories(${CMAKE_BINARY_DIR}/..)
#target_link_libraries(pureclog ring_queue)

add_executable(test_pureclog ${TESTSRC})
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
	target_link_libraries(test_pureclog pureclog ring_queue pthread)
else()
	target_link_libraries(test_pureclog pureclog ring_queue)
endif()

set(CMAKE_CONFIGURATION_TYPES "Release" "Debug" CACHE STRING "Possible configurations" FORCE)

if(DEFINED CMAKE_BUILD_TYPE)
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
endif()

if(MSVC)
  # Dynamically link the runtime libraries
  add_compile_options(
    $<$<CONFIG:>:/MD>
    $<$<CONFIG:Debug>:/MDd>
    $<$<CONFIG:Release>:/MD>
  )

  # 设置 VisualStudio 链接器->输入 链接库 “从父继承”
  set(CMAKE_CXX_STANDARD_LIBRARIES "$(CMAKE_CXX_STANDARD_LIBRARIES) %(AdditionalDependencies)")
endif()

set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR}/install)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/lib/)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_BINARY_DIR}/bin/)

add_definitions(-w)

if(MSVC)
  # remove_definitions(/W3)
  # add_definitions(/W4)
  add_definitions(/wd4819)
  add_definitions(/wd4244)
  add_definitions(/wd4267)
  add_definitions(-DNOMINMAX)
  add_definitions(-D_CRT_SECURE_NO_WARNINGS)
  add_definitions(-DWIN64)
endif()

# Visual Studio 分组
# SOURCE_GROUP("" FILES ${Root_FILES})
# SOURCE_GROUP(Dir\\SubDir FILES ${SubDir_FILES})

# set_target_properties(foo PROPERTIES COMPILE_FLAGS "/Od")

# 添加 自定义PropertySheet文件 到 Visual Studio
# set_target_properties(foo PROPERTIES VS_USER_PROPS "${PROJECT_SOURCE_DIR}/main.props")

# set_target_properties(foo PROPERTIES LINK_LIBRARIES "%(AdditionalDependencies)")

# Visual Studio 后期生成事件
# ADD_CUSTOM_COMMAND(
# TARGET foo
# POST_BUILD
# COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_BINARY_DIR}
# COMMAND ${CMAKE_COMMAND} -E copy ${EXAMPLE_BIN_NAME} ${PROJECT_BINARY_DIR}/.
# )
